package single;

/**
 * @author GongXincheng
 * @since 2019-08-02 18:49
 */
public class Demo2 {

    private static volatile Demo2 instance = null;

    private Demo2() {}

    public static Demo2 getInstance() {
        if (instance == null) {
            synchronized (Demo2.class) {
                if (instance == null) {
                    instance = new Demo2();
                }
            }
        }
        return instance;
    }

    public static void main(String[] args) {
        Demo2 instance1 = Demo2.getInstance();
        Demo2 instance2 = Demo2.getInstance();
        System.out.println(instance1 == instance2);
    }

}
